<template>
  <div>
    <el-dialog
      :title="title"
      :visible.sync="dialogVisible"
      width="40%"
      top="8vh"
      center:false
      :before-close="handleClose"
    >
      <el-form label-position="right" label-width="250px" :rules="rules" :model="lookup" ref="lookup">
         <input v-model="lookup.id" hidden>
        <el-row>
          <el-col :span="20">
            <el-form-item label="名称:" prop="name">
              <el-input   placeholder="请输入字典名称" v-model="lookup.name"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="20">
            <el-form-item label="编码:" prop="code">
              <el-input   placeholder="请输入字典编码" v-model="lookup.code"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
         <el-row>
          <el-col :span="20">
            <el-form-item label="排序号:" prop="sortno">
              <el-input   placeholder="请输入排序号"  v-model="lookup.sortno"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="20">
            <el-form-item label="描述信息:" prop="remark">
              <el-input   placeholder="请输入描述信息" type="textarea" v-model="lookup.remark"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose">关闭</el-button>
        <el-button type="primary"  @click="handleSave(lookup)">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
export default {
  name: "vDialog",
  //初始化返回数据
  data() {
    return {
      cronPopover:false,
      rules: {
        name: [
          { required: true, message: "请输入字典名称", trigger: "blur" },
          { min: 1, max: 50, message: "长度在 1 到 50 个字符", trigger: "blur" }
        ],
        code: [
          { required: true, message: "请输入字典编码", trigger: "blur" },
          { min: 1, max: 10, message: "长度在 1 到 10 个字符", trigger: "blur" }
        ],
        sortno: [
          { required: true, message: "请输入排序号", trigger: "blur" },
          { min: 1, max: 500, message: "长度在 1 到 500 个字符", trigger: "blur" }
        ]
      }
    };
  },
  //父组件传过来的数据属性
  props: {
    dialogVisible: {
      type: Boolean,
      required: true
    },
    title: {
      type: String,
      required: true
    },
    lookup: Object
  },
  components: {
  },
  //方法
  methods: {
    //关闭按钮
    handleClose() {
      this.$emit("dialogClose", this.dialogVisible);
    },
    //保存按钮
    handleSave(lookup) {
      this.$refs.lookup.validate((valid) => {
          if(valid){
            let url = "/add";
            if (lookup.id != null && "" != lookup.id) {
              url = "/update";
            }
            var _this = this;
            this.axios
              .post(this.HOST + url, lookup)
              .then(function(res) {
                _this.$message({
                  message: "操作成功!"+res,
                  type: " "
                });
                _this.$emit("dialogSave", _this.dialogVisible);
              })
              .catch(function(err) {
                _this.$message.error("操作失败"+err);
              });
          }
      });
    },
  }
};
</script>
<style >
.el-dialog__header {
  text-align: center;
}
</style>
